#ifndef EXCEPT_H
#define EXCEPT_H

#include <boost/any.hpp>
#include <exception>
#include <boost/shared_ptr.hpp>



typedef unsigned long     TypeError;

#define UNDEF       0   // Unknown error
#define ECONV       1  // Wrong conversion requested
#define ISYMBOL     2 // Illegal symbol

// Exception throwned for illegal casting
class RnException : public boost::bad_any_cast {
 public :
  RnException(TypeError e, const char* msg = NULL, boost::bad_any_cast boostex = boost::bad_any_cast())
    : code(e), boost::bad_any_cast(boostex) {
    if(!msg)
      return;
    m = boost::shared_ptr<char>(new char[strlen(msg)]);
    strncpy((char*)get_pointer(m), msg, strlen(msg));
  }
    virtual const char* what() const throw() {
      return (const char*)get_pointer(m);
    }
    TypeError getCode() const {
      return code;
    }
 private:
    TypeError code;
    boost::shared_ptr<char> m;
};


#endif
